<template>
  <div class="my-server">
    <!-- 足迹与收藏模块 -->
    <div class="module-header">
      <h3 class="header-title">足迹与收藏</h3>
      <div class="header-actions">
        <span class="more-btn" @click="handleMore">更多</span>
      </div>
    </div>
    <div class="group-items footprint-group">
      <div
        class="item"
        v-for="(item, index) in item1s"
        :key="index"
        :data-tip="item.tip"
        @mouseenter="handleItemHover(item, true)"
        @mouseleave="handleItemHover(item, false)"
      >
        <div class="item-icon">
          <i class="iconfont" :class="item.icon"></i>
        </div>
        <span class="item-text">{{ item.text }}</span>
      </div>
    </div>

    <!-- 生活服务模块 -->
    <div class="module-header">
      <h3 class="header-title">生活服务</h3>
      <div class="header-actions">
        <span class="more-btn" @click="handleServiceMore">更多</span>
      </div>
    </div>
    <div class="group-items service-group">
      <div
        class="item"
        v-for="(item, index) in item2s"
        :key="index"
        :data-tip="item.tip"
        @mouseenter="handleItemHover(item, true)"
        @mouseleave="handleItemHover(item, false)"
      >
        <div class="item-icon">
          <i class="iconfont" :class="item.icon"></i>
        </div>
        <span class="item-text">{{ item.text }}</span>
      </div>
    </div>

    <!-- 指示器 -->
    <div class="indicators">
      <span class="dot active"></span>
      <span class="dot"></span>
    </div>
  </div>
</template>
<script setup>
import { ref } from 'vue';

const item1s = [
  { text: '浏览记录', icon: 'icon-zuji', tip: '查看您的浏览足迹' },
  { text: '商品收藏', icon: 'icon-shoucang', tip: '查看收藏的商品' },
  { text: '店铺关注', icon: 'icon-dianpuguanzhu', tip: '查看关注的店铺' },
];
const item2s = [
  { text: '话费', icon: 'icon-huafei', tip: '管理话费相关' },
  { text: '机票', icon: 'icon-jipiao', tip: '查询、预订机票' },
  { text: '酒店', icon: 'icon-jiudian', tip: '查询、预订酒店' },
  { text: '企业购', icon: 'icon-qiye1', tip: '企业采购入口' },
  { text: '加油卡', icon: 'icon-jiayou', tip: '加油卡管理' },
  { text: '电影票', icon: 'icon-dianyingpiao_line', tip: '购买、管理电影票' },
];

// 用于存储hover状态，控制提示显示
const hoverItem = ref(null);

// 处理鼠标悬浮事件
const handleItemHover = (item, isEnter) => {
  if (isEnter) {
    hoverItem.value = item;
  } else {
    hoverItem.value = null;
  }
};

// 处理“更多”按钮点击
const handleMore = () => {
  console.log('点击了足迹与收藏的更多按钮');
};

const handleServiceMore = () => {
  console.log('点击了生活服务的更多按钮');
};
</script>
<style scoped lang="scss">
.my-server {
  background-color: #fff;
  margin-top: 25px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  overflow: hidden;

  // 模块头部：标题 + 操作区
  .module-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #f2f2f2;

    .header-title {
      font-size: 16px;
      font-weight: 500;
      color: #333;
      margin: 0;
    }

    .header-actions {
      .more-btn {
        color: #409eff;
        cursor: pointer;
        &:hover {
          opacity: 0.8;
        }
      }
    }
  }

  // 功能组通用样式
  .group-items {
    display: flex;
    flex-wrap: wrap;
    position: relative;

    // 单个功能项
    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 20px 0;
      cursor: pointer;
      transition: all 0.3s ease;
      position: relative;

      &:hover {
        background-color: #fafafa;
      }

      // 图标容器
      .item-icon {
        font-size: 28px;
        margin-bottom: 8px;

        .iconfont {
          vertical-align: middle;
          color: #cec0b0;
        }
      }

      .item-text {
        font-size: 14px;
        color: #333;
      }

      // 提示框样式
      &::after {
        content: attr(data-tip);
        position: absolute;
        background-color: rgba(0,0,0,0.7);
        color: #fff;
        padding: 6px 12px;
        border-radius: 4px;
        font-size: 12px;
        bottom: -32px;
        left: 50%;
        transform: translateX(-50%);
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
      }

      &:hover::after {
        opacity: 1;
      }
    }
  }

  // 足迹与收藏组 - 三列布局
  .footprint-group {
    .item {
      width: 33.333%;
    }
    border-bottom: 1px solid #f2f2f2;
  }

  // 生活服务组 - 三列两行布局
  .service-group {
    .item {
      width: 33.333%;
      height: 100px; // 固定高度确保两行整齐
    }
  }

  // 指示器样式
  .indicators {
    display: flex;
    justify-content: center;
    padding: 10px 0;

    .dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background-color: #ddd;
      margin: 0 4px;
      cursor: pointer;

      &.active {
        background-color: #cec0b0;
      }
    }
  }
}
</style>
